import re
import requests
import sys
import io
from bs4 import BeautifulSoup

# 解决print输出 特殊符号 报错情况
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='gb18030')

url = "https://api.bilibili.com/x/v1/dm/list.so?oid=249509876&date2020-10-26"
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36'}

content = requests.get(url=url, headers=headers).content.decode('utf-8')
bs4_data = BeautifulSoup(content, "lxml")

# 获取到第一个 d标签
print(bs4_data.d)

# 获取到第一个 d标签 的属性
print(bs4_data.d['p'])

# 获取到第一个 d标签 的内容
print(bs4_data.d.get_text())

# 根据标签名称获取所有对应的标签
all_d = bs4_data.find_all('d')
# print(all_d)

# 根据属性选择所有
all_p = bs4_data.find_all(attrs={'p': '2958.49000,1,25,16777215,1603681118,0,77914aae,40128449619165187'})
# print(all_d)

# 根据 css 选择器 选择所有
css_all = bs4_data.select('d')
# print(css_all)
